/**
 * ============================================================
 * 版权：Autohome 版权所有 (c) 2014 - 2015
 * 文件：com.athm.framework.action.BaseModel.java
 * 所含类: BaseModel.java
 * 修改记录：
 * 日期 作者 内容
 * =============================================================
 * 2012-2-16 zhangyongxin 创建文件，实现基本功能
 * ============================================================
 */

package com.quanyou.base.framework.dao.model;


import com.quanyou.base.framework.dao.domain.BaseDomain;

import java.util.*;

/**
 * <p> 类名 </p>
 * <p/>
 * <p> 类用途详细说明 </p>
 * <p/>
 * <p> Copyright: 版权所有 (c) 2014 - 2015 </p>
 * <p> Company: Das Master </p>
 *
 * @author zhangyongxin
 * @version 1.0
 */

public class BaseModel<E extends BaseDomain> {

    protected Integer id;

    private Map<String, String> associates = new HashMap<>();

    /**
     * 模型对应的实体
     */
    private E paramEntity;

    // private Class<E> paramEntityClass;

    /**
     * 查询默认的开始时间
     */
    private Date startTime;

    /**
     * 查询默认的结束时间
     */
    private Date endTime;

    /**
     * 时间查询字段
     */
    private String columTimeName;

    /**
     * 是否自定义查询,默认是不需要自定义查询
     */
    private Boolean customeTime = false;

    /**
     * 动态查询列表
     */
    private List<QueryDefination> queryDefinationList = new ArrayList<QueryDefination>();

    public BaseModel() {
    }

    public BaseModel(E paramEntity) {
        this.paramEntity = paramEntity;
        translateResult();
    }

    public Boolean getCustomeTime() {
        return customeTime;
    }

    public void setCustomeTime(Boolean customeTime) {
        this.customeTime = customeTime;
    }

    /**
     * <p>对需要显示翻译的进行转化</p>
     */
    public void translateResult() {
        translate(this);
    }

    protected void translate(BaseModel<E> mm) {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public E getParamEntity() {
        return paramEntity;
    }

    public E getPe() {
        return paramEntity;
    }

    public void setParamEntity(E paramEntity) {
        this.paramEntity = paramEntity;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public List<QueryDefination> getQueryDefinationList() {
        return queryDefinationList;
    }

    public void setQueryDefinationList(List<QueryDefination> queryDefinationList) {
        this.queryDefinationList = queryDefinationList;
    }

    public void addQueryDefination(QueryDefination queryDefination) {
        this.queryDefinationList.add(queryDefination);
    }

    /**
     * <p>将Boolean转换成String类型，null-->-1,true-->1,false-->0</p>
     *
     * @param value
     * @return String
     */
    protected String booleanToString(Boolean value) {
        if (null == value) {
            return "";
        }
        if (!value) {
            return "F";
        }
        if (value) {
            return "T";
        }
        return "F";
    }

    protected String booleanToStringCHN(Boolean value) {
        if (null == value) {
            return "";
        }
        if (!value) {
            return "否";
        }
        if (value) {
            return "是";
        }
        return "否";
    }

    /**
     * <p>将String转换成Boolean类型，""-->null,T\0-->true,F\1-->false<br></p>
     *
     * @param value
     * @return Boolean
     */
    protected Boolean stringToBoolean(String value) {
        if ("".equals(value)) {
            return null;
        } else if ("F".equals(value) || "1".equals(value)) {
            return false;
        } else if ("T".equals(value) || "0".equals(value)) {
            return true;
        } else {
            return null;
        }
    }

    public String getColumTimeName() {
        return columTimeName;
    }

    public void setColumTimeName(String columTimeName) {
        this.columTimeName = columTimeName;
    }

    public Map<String, String> getAssociates() {
        return associates;
    }

    public void addAssociate(String name) {
        associates.put(name, "1");
    }

}
